// 防抖
let timeoutId;
export function debounce(func, wait = 500) {
	return function(...args) {
		const context = this;
		clearTimeout(timeoutId);
		timeoutId = setTimeout(() => {
			func.apply(context, args);
		}, wait);
	};
}

// 节流
let inThrottle = false;
export function throttle(func, limit = 500) {
	return function(...args) {
		const context = this;
		if (!inThrottle) {
			func.apply(context, args);
			inThrottle = true;
			setTimeout(() => {
				inThrottle = false;
			}, limit);
		}
	};
}